import { useState, useEffect } from 'react';
const useSessionStorage = (key: string, fallback?: any) => {
   // 获取状态
   const [val, setVal] = useState(
    JSON.parse(window.sessionStorage.getItem(key) || fallback )
   )
   useEffect(() => {
     window.sessionStorage.setItem(key, JSON.stringify(val))
   }, [key, val])
   // 更新状态
   return [val, setVal]
}

export default useSessionStorage